@echo off
setlocal enabledelayedexpansion

:: 获取当前日期，格式化为YYYYMMDD
set CURRENT_DATE=%date:~-4,4%%date:~-7,2%%date:~-10,2%

:: 确保logs目录存在
if not exist "%~dp0logs" mkdir "%~dp0logs"

:checkService
sc query "360LASAgent" | findstr /I "RUNNING" > nul
if errorlevel 1 (
    echo %date% %time% - 360LASAgent服务未运行，尝试启动... >> "%~dp0logs\check_health-%CURRENT_DATE%.log"
    sc start "360LASAgent" >> "%~dp0logs\check_health-%CURRENT_DATE%.log" 2>&1
) else (
    echo %date% %time% - 360LASAgent服务正在运行。 >> "%~dp0logs\check_health-%CURRENT_DATE%.log"
)

:: 等待10秒后再次检查
timeout /t 10 /nobreak > nul
goto checkService